package com.gkr.shopping.controller;

import java.util.List;

import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.gkr.shopping.bean.Order;
import com.gkr.shopping.service.OrderService;



@Controller
@RequestMapping("/order")
public class OrderController {
	
	@Autowired
	private OrderService orderService;
	
	 @RequestMapping(value="/checkOrder.do")
     public  String checkOrder(String orderInfo,HttpSession session) {
		 
		  try {
			  session.setAttribute("orderInfo", orderInfo);

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
  	    return "checkOrderInfo";
    }
	
	
	@RequestMapping(value="/orderSubmit.do")
    public  String orderSubmit(HttpSession session,Model model) {
  	   
		  try {
			  
			  String orderInfo = (String)session.getAttribute("orderInfo");
			  System.out.println("orderInfo:"+orderInfo);
			  Order order = orderService.orderSubmit(orderInfo);
			  model.addAttribute("order", order);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		  return "pay";
    }

	  @RequestMapping(value="/showOrder.do")
    public  String showOrder(Model model) { 	
		  
		  try {
			  List<Order> orders = orderService.getOrdersByUserId();
			  model.addAttribute("orders", orders);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		  return "order";
    }
	  
}
